package com.zhuannimei.service;

import android.os.AsyncTask;

/**
 * 异步任务
 * 
 * @author Jack 2013-8-15
 * 
 * 
 */
public class AsyncDataLoader extends AsyncTask<Void, Long, Object> {
	//异步任务封装  --- 回调
	private AsyncDataLoader.Callback mCallback;

	public AsyncDataLoader(AsyncDataLoader.Callback callback) {
		setCallback(callback);
	}

	@Override
	protected Object doInBackground(Void... voids) {
		if (mCallback != null) {
			mCallback.onStart();
		}
		return null;
	}

	@Override
	protected void onPostExecute(Object result) {
		super.onPostExecute(result);
		if (mCallback != null) {
			mCallback.onFinish();
		}
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		if (mCallback != null) {
			mCallback.onPrepare();
		}
	}

	public void setCallback(AsyncDataLoader.Callback callback) {
		this.mCallback = callback;
	}

	public interface Callback {
		//异步任务执行前操作
		public void onPrepare();
		//异步任务执行中
		public void onStart();
		//异步任务执行后
		public void onFinish();
	}
}
